package com.cykj.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Configuration
public class RateLimitConfig {
    @Bean
   public KeyResolver userKeyResolver() {
       KeyResolver keyResolver= new KeyResolver(){

            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
                System.out.println(ip);
                return Mono.just(ip);
            }
        };
       return keyResolver;
    }
}
